$().ready(function () {
    // 在键盘按下并释放及提交后验证提交表单
    var obj = $("#myform").validate({
        rules: {

            username: {
                required: true,
                isName: true
            },
            password: {
                required: true,
                isPwd: true
            },
            repwd: {
                required: true,
                minlength: 5,
                equalTo: "#mypwd"
            },
            email: {
                required: true,
                isEmail: true,
            },
            phone: {
                required: true,
                isPhone: true
            }
            // topic: {
            //     required: "#newsletter:checked",
            //     minlength: 2
            // },
            // agree: "required"
        },
        messages: {
            username: {
                required: "输入用户名了没",

            },
            password: {
                required: "输入密码了没",

            },
            repwd: {
                required: "请验证输入密码",
                minlength: "密码长度不能小于 5 个字符",
                equalTo: "两次密码输入不一致"
            },
            email: {
                required: "输入邮箱了没？"
            },
            phone: {
                required: "输入电话号码"
            }
            // agree: "请接受我们的声明",
            // topic:"请选择两个主题"
        },
        submitHandler:function(form){
            $(".inner-box2").show() 
        }    
    })
    $(".btn1").click(function () {
        $(".inner-box1").show()
        $(".inner-box").hide()
        $(".white-main ul .li2").addClass("xxkxg").siblings().removeClass("xxkxg")
    })
    $(".btn2").click(function(){
        let bool =obj.form()
        if(bool){
            $(".inner-box2").show()
            $(".inner-box1").hide()
            $(".white-main ul .li3").addClass("xxkxg").siblings().removeClass("xxkxg")
        }
    })
    jQuery.validator.addMethod(
        "isName",
        function (value, element) {
            var tel = /^[a-zA-Z0-9_-]{6,12}$/;
            return this.optional(element) || (tel.test(value));
        }, "请正确输入用户名");
    jQuery.validator.addMethod(
        "isPhone",
        function (value, element) {
            var tel = /^1([38]\d|5[0-35-9]|7[3678])\d{8}$/;
            return this.optional(element) || (tel.test(value));
        }, "请正确输入手机号");
    jQuery.validator.addMethod(
        "isPwd",
        function (value, element) {
            var tel = /^[a-zA-Z0-9_-]{8,16}$/;
            return this.optional(element) || (tel.test(value));
        }, "请正确输入密码");
    jQuery.validator.addMethod("isEmail", function (value, element) {
        var tel = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/
        return this.optional(element) || (tel.test(value));
    }, "请正确填写您的邮政编码");
    /^1([38]\d|5[0-35-9]|7[3678])\d{8}$/;
});